package com.laomeng.service.impl;


import com.grpc.lib.hello.HelloRequest;
import com.grpc.lib.hello.HelloResponse;
import com.grpc.lib.hello.HelloServiceGrpc;
import com.grpc.lib.tian.TianResponse;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;


@GrpcService
public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {


    private static final Logger LOG = LoggerFactory.getLogger(HelloServiceImpl.class);

    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
        String name = request.getName();
        LOG.info("received client name is " + name);
        Map<Integer,String>map=new HashMap<>();
        map.put(1,"123");
        Map<Integer,String>map1=new HashMap<>();
        map.put(2,"456");
        HelloResponse response = HelloResponse.newBuilder()
                .setCode("0000")
                .setMessage("hello "+ name)
                .addResponse(TianResponse.newBuilder().putAllMaps(map).putAllMaps(map1).build())
                .build();
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
